<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>JQuery中使用AJAX</title>
    <script src="https://code.jquery.com/jquery-3.6.0.js"></script>
</head>

<body>
    <h1>JQuery中使用AJAX</h1>
    <input type="button" value="Jquery_get方法" onclick="test_get()">
    <input type="button" value="Jquery_get_args_str" onclick="test_get_args_str()">
    <input type="button" value="Jquery_get_args_json" onclick="test_get_args_json()"><br>
    <input type="button" value="Jquery_post_args_str" onclick="test_post_args_str()">
    <input type="button" value="Jquery_post_args_json" onclick="test_post_args_json()"><br>
    <script>
        function test_get() {
            $.get(
                'http://httpbin.org/get',
                function (resp) {
                    console.log(resp)
                }
            )
        }
        // get 请求传递str参数
        function test_get_args_str(){
            $.get(
                'http://httpbin.org/get',
                'name=sxt&pwd=123',
                function (resp) {
                    console.log(resp)
                }
            )
        }
        // get 请求传递json参数
        function test_get_args_json(){
            $.get(
                'http://httpbin.org/get',
                {"name":"sxt","pwd":123},
                function (resp) {
                    console.log(resp)
                }
            )
        }
        // post 请求传递str参数
        function test_post_args_str(){
            $.post(
                'http://httpbin.org/post',
                'name=sxt&pwd=123',
                function (resp) {
                    console.log(resp)
                }
            )
        }
        // post 请求传递json参数
        function test_post_args_json(){
            $.post(
                'http://httpbin.org/post',
                {"name":"sxt","pwd":123},
                function (resp) {
                    console.log(resp)
                }
            )
        }
    </script>
</body>

</html>